<%@ page language="java" import="java.util.*" import="java.sql.*" pageEncoding="UTF-8" %>
<jsp:useBean id="pos_post" scope="page" class="software.Pos_post"/>
<jsp:useBean id="pos_rep" scope="page" class="software.Rep_Reply"/>
<%
	int id_post=1,id_user=0,Page=1,Tot_page=1,refloor=-1;
	request.setCharacterEncoding("UTF-8");
	String plates =request.getParameter("id");
 	String content =request.getParameter("content");
	try{
		Page=Integer.parseInt(request.getParameter("page"));
		refloor=Integer.parseInt(request.getParameter("refloor"));
	}catch(Exception e){
	}
	try{
	id_post=Integer.parseInt(plates);
	}catch(Exception e){
		// 非法操作跳转
		response.sendRedirect("error.jsp");
	}
 	pos_post.Pos_Read(id_post);
	if(content!=null){
		try{
		 id_user=(Integer)session.getAttribute("ID");
		 pos_rep.setContent(content);
		 pos_rep.setID_User(id_user);
		 pos_rep.setID_Post(id_post);
		 pos_rep.setRep_Floor(refloor);
		 pos_rep.ReplyInsert();	
		 pos_post.setNum_Reply(pos_post.getNum_Reply()+1);
		}catch(Exception e){
			 out.print("<script>alert('请先登录后发表回复！')</script>");
			e.printStackTrace();
		}
	}
	if(pos_post.getID_User()<1)
	{
		response.sendRedirect("index.jsp");
		
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>软件开发交流平台</title>
    <link href="../css/post.css" rel="stylesheet" type="text/css" />
    <script charset="utf-8" src="../kindeditor/kindeditor-min.js"></script>
		<script charset="utf-8" src="../kindeditor/lang/zh_CN.js"></script>
		<script>
			var editor;
			KindEditor.ready(function(K) {
				editor = K.create('textarea[name="content"]', {
					resizeType : 1,
					allowPreviewEmoticons : false,
					allowImageUpload : false,
					items : [
						'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
						'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
						'insertunorderedlist', '|', 'emoticons', 'link']
				});
			});
		</script>
	<script type="text/javascript">
	window.onload = function(){
	if(<%=refloor%>!=-1)
	{
		form_reply.content.focus();
	}
	}
	</script>	
	<script type="text/javascript">
	function checkrp(){
		if(form_reply.content.value==""){
			alert("必须输入内容");
			return false;
		}
		else{
			return true;
		}
	}
	</script>
  </head>
  <body>
<jsp:include page="head.jsp" />
<div id="contianer">
 <div id="left"><img src="../images/post/post_bj1.jpg" width="164" height="500" /></div>
    <div id="center">
        <div id="center_head">
            <div style="border:0px; margin:0px; padding:0px; float:left;">
            <img src="../images/post/post_center_header1.jpg" width="695" height="59" border="0" usemap="#Map_Center_Top" />
              <map name="Map_Center_Top" id="Map_Center_Top">
                <area shape="rect" coords="9,34,61,54" href="ft.jsp" />
                <area shape="rect" coords="70,33,119,55" href="post.jsp?id=<%=id_post%>&page=<%=Page %>&refloor=0" />
                <area shape="rect" coords="593,31,660,53" href="plates.jsp?plates=<%=pos_post.getID_Plates()%>" />
              </map>
            </div>
            <table border="0" cellpadding="0" cellspacing="0" style="background-image:url(../images/post/post_center_header2.jpg); border:0px; margin:0px; height:36px; width:695px; float:left; padding-bottom:4px;">
              <tr>
                <td width="63">&nbsp;</td>
                <td width="49"><%=pos_post.getNum_Clicks() %></td>
                <td width="68"><%=pos_post.getNum_Reply() %></td>
                <td width="514"><%=pos_post.getName_Plates() %>--&gt;<%=pos_post.getTitle() %></td>
              </tr>
            </table>
        </div>
        <div id="post">
            <div id="post_user">
                <div id="post_user_photo"><a href="#" style="border:0px; margin-left:6px; margin-top:6px; float:left">
                <%
                 String Phosrc=new String();
               	 String saveurl=request.getRealPath("/")+"Photo"+"\\"+pos_post.getPhoto();
        		 java.io.File file = new java.io.File(saveurl); 	///读入刚才上传的文件///
        		if(file.exists())
	        	{
	        		Phosrc="../Photo/"+pos_post.getPhoto();
	        	}
	        	else Phosrc="../Photo/photo90.jpg";
	        	
                %>
                <img src="<%=Phosrc %>" width="90" height="90" hspace="0" vspace="0" border="0" /></a></div>
                <div id="post_user_information">
                   <table width="90" border="0" cellspacing="0" cellpadding="0" style=" margin-left:10px; font-size:16px;">
                      <tr>
                        <td height="37"><%=pos_post.getName_User() %></td>
                      </tr>
                      <tr>
                        <td height="30">
                        <img src="../images/post/user_grade_moon.jpg" width="15" height="15" />
                        <img src="../images/post/user_grade_star.jpg" width="15" height="15" />
                        <img src="../images/post/user_grade_star.jpg" width="15" height="15" />
                       </td>
                      </tr></table>
                   <table width="62" border="0" cellspacing="0" cellpadding="0" style=" margin-left:12px;">
                      <tr>
                        <td><a href="#"><img src="../images/post/post_user_index.jpg" width="62" height="18" hspace="0" vspace="0" border="0" /></a></td>
                      </tr>
                      <tr>
                        <td><input name="加好友"  value=""type="button" style="background-image:url(../images/post/post_user_friend.jpg); border:0px; height:18px; width:62px;"/></td>
                      </tr>
                      <tr>
                        <td><a href="#"><img src="../images/post/post_user_leavemessage.jpg" width="62" height="18" hspace="0" vspace="0" border="0" /></a></td>
                      </tr>
                  </table>
            </div>
            </div>
            <div id="post_content">
                <div id="post_content_head">
                    <table width="535" height="30" border="0" cellpadding="0" cellspacing="0" style="margin-left:16px; font-size:16px; font-weight:bolder;">
                      <tr>
                        <td width="449"> <%=pos_post.getTim_Post() %></td>
                        <td width="51">楼主</td>
                      </tr>
                    </table>
                </div>
                <div id="post_content_body">
                    <table width="554" border="0">
                      <tr>
                        <td  width="554">
							<div>
								&nbsp;&nbsp;&nbsp;<%=pos_post.getContent() %>
							</div>
						</td>
                      </tr>
                    </table>
                </div>
                <div id="post_content_foot"><img src="../images/post/post_content_foot.jpg" width="554" height="28" border="0" usemap="#Map_Poster" />
                 <map name="Map_Poster" id="Map_Poster">
                    <area shape="rect" coords="29,0,82,22" href="post.jsp?id=<%=id_post%>&page=<%=Page%>&refloor=0" />
                    <area shape="rect" coords="101,-2,163,22" href="#" />
                  </map>
                </div>
            </div>
      </div>
             
      <% 
      	 pos_rep.setID_Post(id_post);
 		 pos_rep.ReplyRead(Page-1);	//读取第Page页回复
		 for(int i=0;i<pos_rep.getNum_Page();i++)
		 {
		 	pos_rep.RepNext();
			int Floor =pos_rep.getRep_Floor();
		 %>
        <div id="post">
            <div id="post_user">
                <div id="post_user_photo">
                	<a href="#" style="border:0px; margin-left:6px; margin-top:6px; float:left">
                	 <%
		                 String Pho_Replies=new String();
		               	 String saveurls=request.getRealPath("/")+"Photo"+"\\"+pos_rep.getPhoRep();
		        		 java.io.File files = new java.io.File(saveurls); 	//读入刚才上传的文件
		        		if(files.exists())
			        	{
		        			Pho_Replies="../Photo/"+pos_rep.getPhoRep();
			        	}
			        	else Pho_Replies="../Photo/photo90.jpg";
			        	
		                %>
                	<img src="<%=Pho_Replies %>" width="90" height="90" hspace="0" vspace="0" border="0" />
                	</a>
                </div>
                <div id="post_user_information">
                   <table width="90" border="0" cellspacing="0" cellpadding="0" style=" margin-left:10px; font-size:16px;">
                      <tr>
                        <td height="37"><%=pos_rep.getNam_User() %></td>
                      </tr>
                      <tr>
                        <td height="30"><img src="../images/post/user_grade_moon.jpg" width="15" height="15" /><img src="../images/post/user_grade_star.jpg" width="15" height="15" /><img src="../images/post/user_grade_star.jpg" width="15" height="15" /></td>
                      </tr></table>
                   <table width="62" border="0" cellspacing="0" cellpadding="0" style=" margin-left:12px;">
                      <tr>
                        <td><a href="#"><img src="../images/post/post_user_index.jpg" width="62" height="18" hspace="0" vspace="0" border="0" /></a></td>
                      </tr>
                      <tr>
                        <td><input name="加好友"  value=""type="button" style="background-image:url(../images/post/post_user_friend.jpg); border:0px; height:18px; width:62px;"/></td>
                      </tr>
                      <tr>
                        <td><a href="#"><img src="../images/post/post_user_leavemessage.jpg" width="62" height="18" hspace="0" vspace="0" border="0" /></a></td>
                      </tr>
                  </table>
            </div>
            </div>

            <div id="post_content">
                <div id="post_content_head">
                    <table width="535" height="30" border="0" cellpadding="0" cellspacing="0" style="margin-left:16px; font-size:16px; font-weight:bolder;">
                      <tr>
                        <td width="449"><%=pos_rep.getTim_Post() %></td>
                        <td width="51">
                        <%
                        Floor=pos_rep.getFloor();
						 if(Floor==1) out.print("沙发");
                        else if(Floor==2)out.print("板凳");
                        else if(Floor==3)out.print("地板");
                        else out.print("#"+Floor+"楼");
                		 %>
                        </td>
                      </tr>
                    </table>
                </div>
                <div id="post_content_body">
                    <table width="554" border="0">
                      <tr><%if(pos_rep.getRep_Floor()>0) out.print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;对#"+pos_rep.getRep_Floor()+"楼的回复<br/>"); %>
                        <td width="554">
                        <div style="width:554px;">&nbsp;&nbsp;&nbsp;<%=pos_rep.getContent() %></div>
                        </td>
                      </tr>
                    </table>
                </div>
                <div id="post_content_foot"><img src="../images/post/post_content_foot.jpg" width="554" height="28" border="0" usemap="#Maps<%=Floor%>" />
               	<map name="Maps<%=Floor%>" id="Maps<%=Floor%>">
                    <area shape="rect" coords="29,0,82,22" href="post.jsp?id=<%=id_post%>&page=<%=Page%>&refloor=<%=Floor %>" />
                  </map>
                </div>
            </div>
      </div>	
     <%} %>
    	<div style="margin-left:200px; width:500px;float:left; height:20px;">     
     <% 
      	Tot_page=(pos_post.getNum_Reply()-1)/10+1;
		if (Tot_page>=1){
		if(pos_post.getNum_Reply()==0){
			out.print("当前没有回复");	}
		else{
			out.print("当前第"+Page+"页　");
			out.print("共"+Tot_page+"页　");
		}
		if(Page!=1) {
		  out.print("<a href=post.jsp?id="+id_post+"&page="+1+">首页</a>　");
		  out.print("<a href=post.jsp?id="+id_post+"&page="+(Page-1)+">上一页</a>　");
		 }
		if(Page!=Tot_page){
		 out.print("<a href=post.jsp?id="+id_post+"&page="+(Page+1)+">下一页</a>　"); 
		 out.print("<a href=post.jsp?id="+id_post+"&page="+Tot_page+">尾页</a>　");
		 } 
      
		} 
	%></div>
        <div id="center_foot">
            <div style=" border:0px; padding:0px;
            margin:0px;"><img src="../images/post/post_center_foot.jpg" width="695" height="38" border="0" usemap="#Map_Reply" />
              <map name="Map_Reply" id="Map_Reply">
                <area shape="rect" coords="10,14,62,33" href="ft.jsp" />
                <area shape="rect" coords="70,16,120,32" href="post.jsp?id=<%=id_post%>&page=<%=Page %>&refloor=0" />
                <area shape="rect" coords="598,17,662,35" href="plates.jsp?plates=<%=pos_post.getID_Plates()%>" />
              
              </map>
             </div>
            <form name="form_reply" method="post" action="post.jsp?id=<%=id_post%>&page=<%=Page %>&refloor=<%=refloor %>" onsubmit="return checkrp()">
            <div style=" background-color:#FFF2CE; width:695px; border:0px; padding:0px; height:240px;">
                <div id="post_user">
                <%
                /*
                ** 给发帖 确定回复者的头像
                */
	                String Pho_rep=null;
					String sads=request.getRealPath("/")+"Photo"+"\\"+(String)session.getAttribute("PhoSrc");
	        		java.io.File file1 = new java.io.File(sads); 	//读入刚才上传的文件
	        		if(file1.exists())
		        	{
	        			Pho_rep="../Photo/"+(String)session.getAttribute("PhoSrc");
		        	}
		        	else Pho_rep="../Photo/photo90.jpg";
                %>
                   <div id="post_user_photo"><input name="photo"  type="image" src="<%=Pho_rep%>" style="margin-left:6px; height:90px;width:90px; margin-top:6px;"/></div>
                </div>
                <div id="post_content">
                    <div id="post_content_body">
                      <textarea name="content" cols="1" rows="" style="height:220px;visibility:hidden; width:552px; border:0px; margin-left:4px;"></textarea>               
                    </div>
                </div>
            </div> 
            <div style="width:695px; height:50px; background-color:#FFF2CE; border:0px; margin:0px;">
	            <input  value="" type="submit" style="background-image:url(../images/post/post_button_fbhf.jpg); width:75px; height:25px; margin-top:14px; margin-left:165px; border:0px;"/>
	            <input  value="" type="reset" class="button"  style="background-image:url(../images/post/post_button_qx.jpg); margin-top:14px; margin-left:22px; width:75px; height:25px; border:0px;"/>
	        </div>
       	 	</from>
       	 	</div>
  </div>
 <div id="right"><img src="../images/post/post_bj2.jpg" width="163" height="500" /></div> 
 <div style="clear:both;"></div>  
</div>
 	<jsp:include page="footer.jsp" />
  </body>
</html>
